package adapter

import (
	"fmt"
	"github.com/stretchr/testify/assert"
	"migration-tool/common"
	"testing"
)

func TestStart(t *testing.T) {
	cfg, err := common.ParseConfig(TestDefaultConfigPath)
	assert.Equal(t, err, nil)
	repoInfo := RepoInfo{
		RepoId:           2754725,
		RepoGroupName:    "agit",
		RepoName:         "test_migration",
		CodeCloneHttpUrl: "http://gitlab.alibaba-inc.com/agit/test_migration.git",
		WikiEnable:       true,
	}

	args := DefaultAdapterArgs{
		RepoInfo: &repoInfo,
	}

	adapter, err := makeDefaultAdapter(&cfg, args)

	err = adapter.Start()
	assert.Equal(t, err, nil)
	err = adapter.Stop()
	assert.Equal(t, err, nil)
}

func TestDefaultRepoExportAdapter_makeAllTasks(t *testing.T) {
	cfg, err := common.ParseConfig(TestDefaultConfigPath)
	assert.Equal(t, err, nil)
	repoInfo := RepoInfo{
		RepoId:           2754725,
		RepoGroupName:    "agit",
		RepoName:         "test_migration",
		CodeCloneHttpUrl: "http://gitlab.alibaba-inc.com/agit/test_migration.git",
		WikiEnable:       true,
	}
	args := DefaultAdapterArgs{
		RepoInfo: &repoInfo,
	}

	adapter, err := makeDefaultAdapter(&cfg, args)
	assert.Equal(t, err, nil)

	err = adapter.makeAllTasks()
	assert.Equal(t, err, nil)

	fmt.Println(adapter.tasks)
	for _, k := range adapter.taskProgress {
		fmt.Println(*k)
	}
	//fmt.Println(adapter)
}

func TestNewAoneAdapter(t *testing.T) {
	repoInfo := RepoInfo{
		RepoId:   int64(1549172),
		RepoName: "satellite",
	}

	cfg, err := common.ParseConfig(TestDefaultConfigPath)
	assert.Equal(t, err, nil)
	cfg.BaseConfig.Export = true
	cfg.BaseConfig.UseProgress = true
	args := DefaultAdapterArgs{
		RepoInfo: &repoInfo,
	}
	_, err = makeDefaultAdapter(&cfg, args)
	fmt.Println(err)
}
